package com.example.quartz.basic;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.scheduling.annotation.Scheduled;

public class Testjob {
    public static void main(String[] args) {
        int count = 0;
        //将job包装成jobDetail 通过链式编程设置属性
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .usingJobData("name","wuyou")
                .withIdentity("job1", "group1")
                .usingJobData("count",count)
                .build();
        //设置触发器-每分钟执行1次，一直执行
        Trigger triggerBuilder = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger1")
                .usingJobData("year","26")
                .usingJobData("count1",count)
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(1000).repeatForever())
                .build();

        //设置调度器
        try {
            Scheduler scheduled = StdSchedulerFactory.getDefaultScheduler();
            scheduled.scheduleJob(jobDetail,triggerBuilder);
            scheduled.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }

    }


}
